/**
 * 
 */
package TestCases;

import Tracer.RTColor;
import Tracer.RTVector;
import XMLScene.RTPlane;
import XMLScene.RTSurface;
import junit.framework.TestCase;

/**
 * @author Hongyi Zhao
 * 
 */
public class RTPlaneTest extends TestCase {
	private RTPlane plane = null;
	private RTPlane planeFromPoint = null;

	/**
	 * @param name
	 */
	public RTPlaneTest(String name) {
		super(name);
	}

	protected void setUp() throws Exception {
		super.setUp();

		plane = new RTPlane(new RTVector(0.0f, 0.0f, 1.0f), 1.0f);
		planeFromPoint = new RTPlane(new RTVector(1.0f, 0.0f, 0.0f),
				new RTVector(1.0f, 0.0f, 0.0f));
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	/**
	 * Test method for getNormal Test it works well after performing getNormal
	 */
	public final void testGetNormal() {
		RTVector normal = plane.getNormal();
		assertTrue(normal.isEqual(new RTVector(0.0f, 0.0f, 1.0f)));

		normal = planeFromPoint.getNormal();
		assertTrue(normal.isEqual(new RTVector(1.0f, 0.0f, 0.0f)));
	}

	/**
	 * Test method for getDistance Test it works well after performing
	 * getDistance
	 */
	public final void testGetDistance() {
		double distance = plane.getDistance();
		assertEquals("Distance wrong", (double) 1.0, distance);

		distance = planeFromPoint.getDistance();
		assertEquals("Distance wrong", (double) 1.0, distance);
	}

	/**
	 * Test method for setDistance Test it works well after performing
	 * setDistance
	 */
	public final void testSetDistance() {
		double distance = 10.0f;
		plane.setDistance(distance);
		assertEquals("Distance wrong", (double) 10.0, plane.getDistance());

		planeFromPoint.setDistance(distance);
		assertEquals("Distance wrong", (double) 10.0, planeFromPoint
				.getDistance());
	}

	/**
	 * Test method for getSurface Test it works well after performing getSurface
	 */
	public final void testGetSurface() {
		assertTrue("Get surface error", planeFromPoint.getSurface()
				.getPigment().getColor().isEqual(new RTColor(0.0f, 0.0f, 0.0f)));
	}

	/**
	 * Test method for setSurface. Test it works well after performing
	 * setSurface
	 */
	public final void testSetSurface() {
		RTSurface surface = new RTSurface(new RTColor(0.0f, 0.0f, 0.0f));
		plane.setSurface(surface);
		assertNotNull(plane.getSurface());
	}
}
